import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class JrAvatar extends StatefulWidget {
  final double size;
  final String url;
  final double borderWidth;
  final Widget? attachment;
  final VoidCallback? onTap;

  const JrAvatar({Key? key, required this.size, required this.url, this.borderWidth = 0.0, this.attachment, this.onTap})
      : super(key: key);

  @override
  State<JrAvatar> createState() => _JrAvatarState();
}

class _JrAvatarState extends State<JrAvatar> {
  double get radius => widget.size.r / 2;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: widget.onTap,
      child: Stack(
        children: [
          Container(
            padding: EdgeInsets.all(widget.borderWidth.w),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(radius)),
              color: Colors.white,
            ),
            child: CircleAvatar(
              backgroundColor: Colors.white,
              radius: (radius - widget.borderWidth).w,
              foregroundImage: (widget.url.isNotEmpty) ? NetworkImage(widget.url) : null,
            ),
          ),
          if (widget.attachment != null) Positioned(bottom: 0, right: 0, child: widget.attachment!)
        ],
      ),
    );
  }
}
